package logic

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/pkg/jwt"
	"gitee.com/Cauchy_AQ/vxopen/rpc/transform/transform"

	"gitee.com/Cauchy_AQ/vxopen/api/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAvatarLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAvatarLogic {
	return &UserAvatarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAvatarLogic) UserAvatar(req *types.UserAvatarReq) (resp *types.UserAvatarResp, err error) {
	myClaims := l.ctx.Value("MyClaims").(jwt.MyClaims)

	_, err = l.svcCtx.Transformer.UserAvatar(l.ctx, &transform.UserAvatarReq{
		Openid: myClaims.OpenId,
		Mobile: myClaims.Mobile,
		Avatar: req.Avatar,
	})
	if err != nil {
		return nil, err
	}

	return nil, nil
}
